package com.yx.yinshanjinniu.view;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Build;

import com.mobile.auth.gatewayauth.AuthRegisterViewConfig;
import com.mobile.auth.gatewayauth.AuthUIConfig;
import com.mobile.auth.gatewayauth.CustomInterface;
import com.mobile.auth.gatewayauth.PhoneNumberAuthHelper;
import com.yx.yinshanjinniu.base.BaseActivity;
import com.yx.yinshanjinniu.constants.Constant;
import com.yx.yinshanjinniu.utils.auth.BaseUIConfig;

public class DialogBottomConfig extends BaseUIConfig {

    private BaseActivity mBaseActivity;

    public DialogBottomConfig(Activity activity, PhoneNumberAuthHelper authHelper) {
        super(activity, authHelper);
        mBaseActivity = (BaseActivity) activity;
    }

    @Override
    public void configAuthPage() {
        mAuthHelper.removeAuthRegisterXmlConfig();
        mAuthHelper.removeAuthRegisterViewConfig();
        int authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        if (Build.VERSION.SDK_INT == 26) {
            authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_BEHIND;
        }
        updateScreenSize(authPageOrientation);
        int dialogHeight = (int) (mScreenHeightDp * 0.6f);
        //sdk默认控件的区域是marginTop50dp
        int designHeight = dialogHeight - 50;
        int unit = designHeight / 10;
        int logBtnHeight = (int) (unit * 1.2);
        mAuthHelper.addAuthRegistViewConfig("switch_msg", new AuthRegisterViewConfig.Builder()
                .setView(initSwitchView(unit * 6, Constant.DIALOG_BOTTOM))
                .setRootViewId(AuthRegisterViewConfig.RootViewId.ROOT_VIEW_ID_BODY)
                .setCustomInterface(new CustomInterface() {
                    @Override
                    public void onClick(Context context) {
//                        mBaseActivity.showLoginDialogLogic();
                        mAuthHelper.quitLoginPage();
                    }
                })
                .build());
//        mAuthHelper.addAuthRegisterXmlConfig(new AuthRegisterXmlConfig.Builder()
//                .setLayout(R.layout.custom_bottom_dialog_action_bar, new AbstractPnsViewDelegate() {
//                    @Override
//                    public void onViewCreated(View view) {
//                        findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                mAuthHelper.quitLoginPage();
//                                new Handler().postDelayed(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        mBaseActivity.isLoginProcess = false;
//                                    }
//                                },1000);
//                            }
//                        });
//                    }
//                })
//                .build());

        mAuthHelper.setAuthUIConfig(new AuthUIConfig.Builder()
//                .setAppPrivacyOne("《用户协议》", mBaseActivity.mAppAction.getUrlByNewId(CONST.H5_USER_URL))
//                .setAppPrivacyTwo("《风险揭示书》",  mBaseActivity.mAppAction.getUrlByNewId(CONST.H5_RISK_URL))
//                .setAppPrivacyThree("《隐私协议》", mBaseActivity.mAppAction.getUrlByNewId(CONST.H5_PRIVATE_URL))
                .setAppPrivacyColor(Color.GRAY, Color.parseColor("#1577FE"))
                .setPrivacyState(true)
                .setCheckboxHidden(false)
                .setNavHidden(true)
                .setSwitchAccHidden(true)
//                .setLogoImgPath("mytel_app_launcher")
//                .setLogoOffsetY(0)
//                .setLogoWidth(42)
//                .setLogoHeight(42)

                .setNumFieldOffsetY(unit + 90)
                .setNumberSizeDp(22)
                .setSloganHidden(true)
                .setSwitchAccHidden(true)

//                .setSloganText("为了您的账号安全，请先绑定手机号")
//                .setSloganOffsetY(unit * 3)
//                .setSloganTextSizeDp(11)

                .setLogBtnOffsetY(unit * 4 + 15)
                .setLogBtnHeight(44)
                .setLogBtnTextSizeDp(14)
                .setLogBtnText("本机号码一键登录")
                .setLogBtnMarginLeftAndRight(30)
                .setLogBtnBackgroundPath("btn_red_login_selector")

//                .setPageBackgroundPath("dialog_page_background")
                .setAuthPageActIn("in_activity", "out_activity")
                .setAuthPageActOut("in_activity", "out_activity")
                .setVendorPrivacyPrefix("《")
                .setVendorPrivacySuffix("》")
                .setPrivacyBefore("我已阅读并同意")
                .setDialogHeight(dialogHeight)
                .setDialogBottom(true)
                .setScreenOrientation(authPageOrientation)
                .create());
    }
}
